/**
 * @file
 * @author dousha 
 * @date 2021/5/25.
 */

#include "util.h"

uint16_t u16le(const uint8_t *xs) {
	return (xs[1] << 8) | xs[0];
}

uint16_t u16be(const uint8_t *xs) {
	return (xs[0] << 8) | xs[1];
}

int16_t s16le(const uint8_t *xs) {
	return (int16_t) u16le(xs);
}

int16_t s16be(const uint8_t *xs) {
	return (int16_t) u16be(xs);
}

uint16_t u3dot1(float f) {
	if (f < 0) {
		f = -f;
	}
	return (uint16_t) (f * 10.f);
}

int16_t s3dot1(float f) {
	return (int16_t) (f * 10.f);
}

float map(int16_t x, int16_t l, int16_t h) {
	return ((float) (x - l)) / ((float) (h - l));
}

extern float deg2rad(float x) {
	return x * 3.1415926f / 180.f;
}

extern float rad2deg(float x) {
	return x * 180.f / 3.1415926f;
}
